@(pageName: String,
  page: Option[gitbucket.core.service.WikiService.WikiPageInfo],
  repository: gitbucket.core.service.RepositoryService.RepositoryInfo)(implicit context: gitbucket.core.controller.Context)
@import gitbucket.core.view.helpers
@import gitbucket.core.util.FileUtil
@gitbucket.core.html.main(s"${if(pageName.isEmpty) "New Page" else pageName} - ${repository.owner}/${repository.name}", Some(repository)){
  @gitbucket.core.html.menu("wiki", repository){
    <div class="pull-right">
      @if(page.isDefined){
        <a class="btn btn-default" href="@helpers.url(repository)/wiki/@helpers.urlEncode(pageName)/_history">Page History</a>
        <a class="btn btn-danger" href="@helpers.url(repository)/wiki/@helpers.urlEncode(pageName)/_delete" id="delete">Delete Page</a>
      }
    </div>
    <h1 class="body-title"><span class="muted">Editing</span> @if(pageName.isEmpty){New Page} else {@pageName}</h1>
    <form action="@helpers.url(repository)/wiki/@if(page.isEmpty){_new} else {_edit}" method="POST" validate="true" autocomplete="off">
      <span id="error-pageName" class="error"></span>
      <input type="text" name="pageName" value="@pageName" class="form-control" style="font-weight: bold; margin-bottom: 10px;" placeholder="Input a page name." aria-label="Page name"/>
      <div class="muted attachable">
        @gitbucket.core.helper.html.preview(
          repository         = repository,
          content            = page.map(_.content).getOrElse(""),
          enableWikiLink     = true,
          enableRefsLink     = false,
          enableLineBreaks   = false,
          enableTaskList     = false,
          hasWritePermission = false,
          completionContext  = "wiki",
          style              = "height: 400px;",
          styleClass         = "monospace",
          placeholder        = "",
          ariaLabel          = "Page content",
          uid                = 1
        )
      </div>
      <div class="form-group">
        <label for="message">Edit Message</label>
        <input type="text" id="message" name="message" value="" class="form-control" placeholder="(Optional) Write a summary of this edit."/>
      </div>
      <div class="form-group pull-right">
        <input type="hidden" name="currentPageName" value="@pageName"/>
        <input type="hidden" name="id" value="@page.map(_.id)"/>
        <input type="submit" value="Save" class="btn btn-success">
      </div>
    </form>
  }
}
<script>
$(function(){
  try {
    $('#content1').dropzone({
      url: '@context.path/upload/wiki/@repository.owner/@repository.name',
      maxFilesize: @{context.settings.upload.maxFileSize / 1024 / 1024},
      timeout: @{context.settings.upload.timeout},
      clickable: false,
      previewTemplate: "<div class=\"dz-preview\">\n  <div class=\"dz-progress\"><span class=\"dz-upload\" data-dz-uploadprogress>Uploading your files...</span></div>\n  <div class=\"dz-error-message\"><span data-dz-errormessage></span></div>\n</div>",
      success: function(file, id) {
        var attachFile = (file.type.match(/image\/.*/) ? '\n![' + file.name.split('.')[0] : '\n[' + file.name) + '](' + file.name + ')';
        $('#content1').val($('#content1').val() + attachFile);
        $(file.previewElement).prevAll('div.dz-preview').addBack().remove();
      }
    });
    $('.clickable').dropzone({
      url: '@context.path/upload/wiki/@repository.owner/@repository.name',
      maxFilesize: @{context.settings.upload.maxFileSize / 1024 / 1024},
      timeout: @{context.settings.upload.timeout},
      previewTemplate: "<div class=\"dz-preview\">\n  <div class=\"dz-progress\"><span class=\"dz-upload\" data-dz-uploadprogress>Uploading your files...</span></div>\n  <div class=\"dz-error-message\"><span data-dz-errormessage></span></div>\n</div>",
      success: function(file, id) {
        var attachFile = (file.type.match(/image\/.*/) ? '\n![' + file.name.split('.')[0] : '\n[' + file.name) + '](' + file.name + ')';
        $('#content1').val($('#content1').val() + attachFile);
        $(file.previewElement).prevAll('div.dz-preview').addBack().remove();
      }
    });
  } catch(e) {
    if (e.message !== "Dropzone already attached.") {
      throw e;
    }
  }

  $('#delete').click(function(){
    return confirm('Are you sure you want to delete this page?');
  });
});
</script>
